package com.cow.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cow.mapper.OrdersMapper;
import com.cow.pojo.Orders;
import com.cow.pojo.OrdersExample;
import com.cow.service.OrderService;

/**
 * @author 光环and鬼泣
 * @version 2018年6月5日 上午10:09:40
 */
@Service("OrdersService")
public class OrderServiceImpl implements OrderService {

	@Autowired
	private OrdersMapper OrdersMapper = null;

	@Override
	public int createOrder(Orders Orders) throws Exception {
		int result = OrdersMapper.insert(Orders);
		return result;
	}

	@Override
	public List<Orders> getOrderList() throws Exception {
		OrdersExample example = new OrdersExample();
		OrdersExample.Criteria criteria = example.createCriteria();
		example.setOrderByClause("order_addtime desc");
		criteria.andOrderIdIsNotNull();
		List<Orders> OrdersList = OrdersMapper.selectByExample(example);
		return OrdersList;
	}

	@Override
	public List<Orders> getOrderList(String userId) throws Exception {
		OrdersExample example = new OrdersExample();
		OrdersExample.Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		example.setOrderByClause("order_addtime desc");
		List<Orders> OrdersList = OrdersMapper.selectByExample(example);
		return OrdersList;
	}

	@Override
	public Orders getOrder(String orderId) throws Exception {
		Orders order = OrdersMapper.selectByPrimaryKey(orderId);
		return order;
	}

	@Override
	public int updataOrer(Orders order) throws Exception {
		int result = OrdersMapper.updateByPrimaryKey(order);
		return result;
	}

}
